<template>
  <div :class="{'is-mobile': showMobilePage}" class="mode-switch-container">
    <div :class="{'mode-1': mode === defaultUnActiveMode }" class="mode-switch">
      <div
        v-for="(it, idx) in modeList"
        :key="idx"
        :class="{ 'active': mode === it.mode }"
        class="mode-switch-item"
        @click="it.handleClick(it.mode)">
        {{ it.name }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
  props: {
    mode: {
      type: Number,
      default: null
    },
    modeList: {
      // params: mode、name、handleClick
      type: Array,
      default: () => ([])
    },
    defaultUnActiveMode: {
      type: Number,
      default: 1
    }
  },
  computed: {
    ...mapState({
      'showMobilePage': state => state.app.showMobilePage
    })
  }
};
</script>

<style lang="scss" scoped>
.mode-switch-container {
  display: flex;
  align-items: center;
  margin-right: 17px;
  padding-right: 16px;
  box-shadow: 7px 0px 7px -7px rgba(174, 182, 199, 0.7);
  &.is-mobile {
    margin-right: 11px;
    padding-right: 10px;
    padding-left: 10px;
  }
}
.mode-switch {
  height: 30px;
  display: flex;
  align-items: center;
  background: #f5f5f5;
  padding: 0 4px;
  border-radius: 4px;
  position: relative;
  box-shadow: inset 0px 10px 10px -15px #aeb6c7, inset 0px -10px 10px -15px #aeb6c7;
  .mode-switch-item {
    font-size: 12px;
    line-height: 22px;
    width: 44px;
    height: 22px;
    font-weight: 400;
    color: #999999;
    white-space: nowrap;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    z-index: 2;
    transition: color .3s;
    &.active {
      color: #fff;
      font-weight: bold;
    }
  }
  &::after {
    content: '';
    height: 22px;
    width: 44px;
    position: absolute;
    left: 4px;
    border-radius: 4px;
    top: 4px;
    background: #406eff;
    transition: left .3s;
  }
  &.mode-1::after {
    left: 48px;
  }
}
</style>
